********Figure D.2 - Mexico********

*Load data
cd "$reploc/data/created_data"
use mex_full, clear

sort pid_link mxfls
foreach var of varlist rbuc_nga grbrprovAvg_lam0co3 grbrprovSD_lam0co3 inflation{
gen `var'dif=`var'-`var'[_n-1] if mxfls==3 & pid_link==pid_link[_n-1]
}

gen coh_prov_clust=yearprov

*Do these results for primary sample
gen primarysample1=0
replace primarysample1=1 if rbuc_ngadif!=. & grbrprovAvg_lam0co3dif!=. & grbrprovSD_lam0co3dif!=. & inflationdif!=. &  birthyr>=1925 & coh_prov_clust!=.

egen primarysample=total(primarysample1), by(pid_link)

drop if mxfls==.
keep if panel==1
keep if primarysample==1

local usei grbr
local rhsvaruse _lam0co3
local measu Avg SD


keep rbuc* mxfls pid_link inflation imp_age panel birthyr grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co? birthstate yearprov

reshape wide rbuc*  inflation imp_age panel grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co?, i(pid_link) j(mxfls)


local varlist1 rbuc rbuc_nga inflation grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co2 grbrprovSD_lam0co2 grbrprovAvg_lam0co3 grbrprovSD_lam0co3 


foreach var in `varlist1'  {
gen `var'dif=.
replace `var'dif=`var'3-`var'2
}


local ytit "{&Delta} Growth Standard Deviation"
local xtit xtitle("{&Delta} Growth Mean")
local tit title("Relationship between average growth and volatility of growth")


twoway scatter `usei'provSD`rhsvaruse'dif `usei'provAvg`rhsvaruse'dif, ///
`xtit' ytitle(" ")  ///
subtitle(`ytit', position(11) justification(left) size(medsmall)) ///
yscale(titlegap(*5)) yline(0, lpattern(dash) lwidth(thin)) xline(0, lpattern(dash) lwidth(thin)) msize(vsmall) ///
yscale(range(-0.8 0.2)) xscale(range(-1 1)) xlabel(-1.5(0.5)1) ylabel(-0.8(0.2)0.2) graphregion(fcolor(white))

cd "$reploc/results"
graph export FigureD2Mexico.eps, replace
